package com.ceair.flight.refund.util;

import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 
 * @author wanghaipeng
 * 2016-10-06
 *
 */
public class BigDecimalTypeHandler extends org.apache.ibatis.type.BigDecimalTypeHandler{

	@Override
	public BigDecimal getNullableResult(CallableStatement cs, int columnIndex)
			throws SQLException {
		BigDecimal result = super.getNullableResult(cs, columnIndex);
		if(result!=null){
			result=result.setScale(2, BigDecimal.ROUND_DOWN);
		}
		return result;
	}
	
	@Override
	public BigDecimal getNullableResult(ResultSet rs, int columnIndex)
			throws SQLException {
		BigDecimal result = super.getNullableResult(rs, columnIndex);
		if(result!=null){
			result=result.setScale(2, BigDecimal.ROUND_DOWN);
		}
		return result;
	}
	@Override
	public BigDecimal getNullableResult(ResultSet rs, String columnName)
			throws SQLException {
		BigDecimal result = super.getNullableResult(rs, columnName);
		if(result!=null){
			result=result.setScale(2, BigDecimal.ROUND_DOWN);
		}
		return result;
	}
	@Override
	public BigDecimal getResult(CallableStatement cs, int columnIndex)
			throws SQLException {
		BigDecimal result = super.getResult(cs, columnIndex);
		if(result!=null){
			result=result.setScale(2, BigDecimal.ROUND_DOWN);
		}
		return result;
	}
	@Override
	public BigDecimal getResult(ResultSet rs, int columnIndex)
			throws SQLException {
		BigDecimal result = super.getResult(rs, columnIndex);
		if(result!=null){
			result=result.setScale(2, BigDecimal.ROUND_DOWN);
		}
		return result;
	}
	@Override
	public BigDecimal getResult(ResultSet rs, String columnName)
			throws SQLException {
		BigDecimal result = super.getResult(rs, columnName);
		if(result!=null){
			result=result.setScale(2, BigDecimal.ROUND_DOWN);
		}
		return result;
	}
}
